package com.xjust.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xjust.Mapper.PharmacyMapper;
import com.xjust.pojo.DrugInfo;
import com.xjust.pojo.Result;
import com.xjust.pojo.ResultBean;
import com.xjust.service.PharmacyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PharmacyServiceIpml implements PharmacyService {
    @Autowired
    private PharmacyMapper pharmacyMapper;

    //获取发药患者信息
    @Override
    public ResultBean getMediPatients(Integer page, Integer pageSize, String caseNumber, String realName) {
       PageHelper.startPage(page,pageSize);
       Page<Map<String,Object>> pageInfo = pharmacyMapper.selectMediPatients(caseNumber,realName);
       ResultBean pageBean = new ResultBean();
       pageBean.setRows(pageInfo.getResult());
       pageBean.setCount(pageInfo.getTotal());
       return pageBean;
    }
    //获取患者药品信息
    @Override
    public Result getMediDrug(String caseNumber) {
        List<DrugInfo> drugInfoList = pharmacyMapper.getMediDrug(caseNumber);
        return Result.success(drugInfoList);
    }

    //改变药品状态
    @Override
    public Result putIssueMedication(Integer drugId, String caseNumber) {
        boolean updated = pharmacyMapper.putIssueMedication(drugId,caseNumber);
        if (updated) {
            return Result.success("药品状态更新成功");
        } else {
            return Result.error("药品状态更新失败");
        }
    }


}
